In [144]:
import numpy as np
import pandas as pd
import math
import cmath
from scipy.optimize import root
import matplotlib.pyplot as plt
%matplotlib inline
In [4]:
print("Hola")
In [5]:
3/5
Out[5]:
In [6]:
8e-10
Out[6]:
In [7]:
x=800
In [8]:
print("Agnès"*30)
In [9]:
g = "Universidad"
In [10]:
g+"Nacional"
Out[10]:
In [11]:
[1,2,3,4,5,6,7,8,9,10,10,11,12]
Out[11]:
In [12]:
Lista1 = [1,2,3,4,5,6,7,8,9,10,10,11,12]
In [13]:
Lista1[0]
Out[13]:
In [14]:
Lista1[-1]
Out[14]:
In [15]:
Lista1[2:]
Out[15]:
In [16]:
Lista1[3:8]
Out[16]:
In [17]:
matrice1 = np.array([3,10,25,98])
matrice1
Out[17]:
In [18]:
matrice2 = np.array([[2,9,7],[14,9,22]])
matrice2
Out[18]:
In [19]:
matrice2[1][2]
Out[19]:
In [20]:
matrice2[0]
Out[20]:
In [21]:
matrice2[0][0]
Out[21]:
In [22]:
matrice2[0][1]
Out[22]:
In [23]:
if matrice2[0][1] > 3:
print("Superior")
else:
print("Inferior")
In [24]:
if matrice2[0][1] > 3:
print("Superior")
elif matrice2[2][1] < 5:
print("Ok")
else:
pass
In [25]:
if matrice2[0][1] < 3:
print("Superior")
elif matrice2[1][2] > 5:
print("Ok")
else:
print("Non")
In [26]:
if matrice2[0][1] > 3 and matrice2[1][2] > 5:
print("Ok")
In [27]:
def sumar(x,y):
z = x+y
return z
In [28]:
sumar(5,4)
Out[28]:
In [29]:
sumar("Python","Anaconda")
Out[29]:
In [30]:
resultado = sumar(4,5)
In [31]:
resultado*10
Out[31]:
In [32]:
def calcular(numero1,numero2,operacion):
if operacion == "+":
numero3 = numero1 + numero2
elif operacion == "-":
numero3 = numero1 - numero2
return numero3
In [33]:
calcular(1,2,"+")
Out[33]:
In [34]:
calcular(1,2,"-")
Out[34]:
In [35]:
def calcular2(numero1,numero2,operacion):
if operacion == "+":
numero3 = numero1 + numero2
return numero3
elif operacion == "-":
numero3 = numero1 - numero2
return numero3
In [36]:
calcular2(2,5,"-")
Out[36]:
In [37]:
def multiplicar(numero1,numero2):
numero3 = numero1*numero2
return numero3
def cuadrado(numero1):
numero2 = numero1 **4
return numero2
In [38]:
operacion = cuadrado(multiplicar(13,25))
In [39]:
operacion
Out[39]:
In [40]:
elementos = np.array(["numero","palabras",3,2])
In [41]:
for elemento in elementos:
print(elemento)
In [42]:
a = np.linspace(2.0,10.0, num =20)
a
Out[42]:
In [43]:
b = a**4
In [44]:
plt.plot(a,b)
plt.title("Fonction")
plt.xlabel("a")
plt.ylabel("b")
plt.grid(True)
In [45]:
datos = np.random.randn(6,4)
print (datos)
compuestos = ["ethanol","propanol","butanol","butanone","isobutanol","ethylmethylcetone"]
propriedad = ["viscosida","densidad","pression saturante","conductividad"]
In [46]:
tabla_de_datos = pd.DataFrame(data=datos,index= compuestos, columns=propriedad)
tabla_de_datos
Out[46]:
In [47]:
tabla_de_datos["viscosida"]
Out[47]:
In [48]:
tabla_de_datos.describe()
Out[48]:
In [49]:
tabla_de_datos.values
Out[49]:
In [50]:
tabla_de_datos[0:3]
Out[50]:
In [365]:
tabla_de_datos2 = tabla_de_datos.copy()
coefficients = tabla_de_datos2.values
coefficients
Out[365]:
In [380]:
coefficients[:,0]
Out[380]:
In [52]:
tabla_de_datos2[tabla_de_datos2 >0]=-tabla_de_datos2
tabla_de_datos2
Out[52]:
In [53]:
tabla_de_datos
Out[53]:
Proceso de migracion
In [54]:
tabla_de_temperaturas : [10,20,30,40,50,60,70,80,90,100]
In [55]:
Volume = (7*(2+6+1))
Volume
Out[55]:
In [56]:
def Volume(a,b,c,d,e,f,g,h,i,j,k,l):
z = ((7*(a+b+c+d+e+f))+31.5*g+24.5*h+10.5*i+38.5*j+(21*k-l))
return z
In [57]:
Volume(2,6,1,0,0,0,0,0,0,0,0,0)
Out[57]:
In [58]:
def D(phi,PM,T,u,Volume):
x = 1.173e-16*((phi*PM)**0.5)*(T/(u*Volume**0.6))
return x
In [59]:
T1 = np.linspace(10,100,10)
T1
Out[59]:
In [60]:
u = 0.0012
In [61]:
phi = 1.5
In [62]:
PM = 0.0446
In [63]:
D(1.5,0.0446,T1,0.0012,63)
Out[63]:
In [64]:
D(1.5,0.0446,20,0.0012,63)
Out[64]:
In [65]:
D(1.5,0.0446,30,0.0012,63)
Out[65]:
In [66]:
D(1.5,0.0446,40,0.0012,63)
Out[66]:
In [67]:
D(1.5,0.0446,50,0.0012,63)
Out[67]:
In [68]:
D(1.5,0.0446,60,0.0012,63)
Out[68]:
In [69]:
D(1.5,0.0446,70,0.0012,63)
Out[69]:
In [70]:
D(1.5,0.0446,80,0.0012,63)
Out[70]:
In [71]:
Diffusion3 = [2.10487105e-14, 4.20974210e-14, 6.31461315e-14, 8.41948421e-14,1.05243553e-13, 1.26292263e-13, 1.47340974e-13, 1.68389684e-13,1.89438395e-13, 2.10487105e-13]
Diffusion3
Out[71]:
In [72]:
plt.plot(T1,Diffusion3)
plt.title("Diffusion = f(T)")
plt.xlabel("Température en degré")
plt.ylabel("Diffusion")
Out[72]:
In [ ]:
In [73]:
Dif = ["Diffusion"]
In [74]:
tabla_de_diffusion = pd.DataFrame(data=Diffusion3,index=T1,columns = Dif)
tabla_de_diffusion
Out[74]:
In [75]:
tabla_de_diffusion.describe()
Out[75]:
In [76]:
T = np.linspace(273,400,10)
T
Out[76]:
In [77]:
def Viscosite(A,B,C,T):
v = np.exp(A+(B/(C+T)))
return v
In [78]:
Viscosite(-7.37146,2770.25,74.6787,T)
Out[78]:
In [79]:
Viscosité = [1.80931608, 1.0559807 , 0.65980795, 0.43602046, 0.30187114,0.21733649, 0.16175719, 0.12386075, 0.09719506, 0.07791022]
Viscosité
Out[79]:
In [80]:
plt.plot(T,Viscosité)
plt.title("Viscosité = f(T)")
plt.xlabel("Température en k")
plt.ylabel("Viscosité")
Out[80]:
In [81]:
T3 = np.linspace(273,400,5)
T3
Out[81]:
In [82]:
Viscosite(-7.37146,2770.25,74.6787,T3)
Out[82]:
In [83]:
T4 = np.linspace(0,127,5)
T4
Out[83]:
In [84]:
D(1.5,0.0446,T4,0.0012,63)
Out[84]:
In [85]:
Vis1 = ["Viscosité"]
In [86]:
tabla_de_viscosité = pd.DataFrame(data=Viscosité,index=T, columns= Vis1)
tabla_de_viscosité
Out[86]:
In [87]:
tabla_de_viscosité.describe()
Out[87]:
In [88]:
tabla_de_viscosité.mean()
Out[88]:
In [89]:
tabla_de_diffusion.mean()
Out[89]:
Diffusion et viscosité en fonction de T (5 températures)
In [90]:
Viscosité [2:7]
Out[90]:
In [91]:
Diffusion3 [2:7]
Out[91]:
In [92]:
T4 = [10,20,30,40,50]
In [93]:
plt.plot(T4,Viscosité[2:7])
plt.plot(T4,Diffusion3[2:7])
plt.title("Diffusivité et viscosité en fonction de T")
plt.xlabel("Température")
Out[93]:
In [94]:
Diffusion3[2:7]
Out[94]:
In [95]:
tabla1 = pd.DataFrame(data = T4, index = Diffusion3[2:7])
tabla1
Out[95]:
In [96]:
tabla2 = pd.DataFrame(data =T4, index =Viscosité[2:7])
tabla2
Out[96]:
In [97]:
tabla_de_viscosité2 = tabla_de_viscosité.copy()
tabla_de_viscosité2
Out[97]:
In [98]:
tabla_de_viscosité2[tabla_de_viscosité2 >0.494106]
Out[98]:
In [99]:
tabla_de_diffusion2 =tabla_de_diffusion.copy()
tabla_de_diffusion2
Out[99]:
In [100]:
tabla_de_diffusion2[tabla_de_diffusion2>1.157679e-13]
Out[100]:
In [101]:
print("Hoy estoy en la universidad nacional de cordoba")
In [102]:
Universidad1 = "universidad nacional de Cordoba"
In [103]:
Universidad2 = "Institut Universitaire Paul Sabatier"
In [104]:
print("Hoy estoy en la",Universidad)
In [ ]:
print("Antes estaba en el {1} y Hoy estoy en la {0}".format(Universidad1,Universidad2))
In [ ]:
C = 1.4e-4
In [ ]:
print("La concentration de éthanol es de",C)
In [ ]:
print("La concentration d'éthanol est {0}".format(C))
In [ ]:
Densidades = {"ethanol":1.8,"propanol":2.6,"isobutanol":3.4,"methylethylcetone":4.2}
Densidades
In [ ]:
Densidades ["propanol"]
In [ ]:
Densidades.keys()
In [ ]:
Densidades.items()
In [ ]:
for (sustancia,densidad) in Densidades.items():
print("La densidad de {0} es igual a {1}".format(sustancia,densidad))
In [ ]:
Comidades = ["Citron","Chocolat","Pitaya","Muesli","Noix de coco"]
Precios =[2,1,4,5,8]
In [ ]:
zip(Comidades,Precios)
In [ ]:
dict(zip(Comidades,Precios))
In [ ]:
plt.plot(Comidades,Precios)
plt.annotate(s = "me gusta",xy=(2,5))
In [ ]:
a = 8
b = -4
c = 3
D = b**2-4*a*c
x1 = (-b+ D**0.5)/(2*a)
print(x1)
x2 = (-b-D**0.5)/2*a
print(x2)
In [ ]:
str(5)
In [ ]:
int("5")
In [ ]:
int("Cinco")
In [ ]:
valor = int (input("ingresar un numero"))
In [ ]:
valor
In [ ]:
valor
In [ ]:
int(valor)
In [ ]:
while True:
try:
x = int(input("Ingresar un numero"))
print("Correct")
break
except ValueError:
print("Incorrect")
In [ ]:
i = 0
while True:
print(i)
if i >= 10:
break
i = i+1
In [ ]:
In [ ]:
a = int(input("ingresar un numero"))
b = int(input("ingresar un numero"))
c = int(input("ingresar un numero"))
D = b**2-(4*a*c)
print("D =",D)
if D < 0:
print ("Pas de solutions reelles")
elif D == 0:
x = (-b+math.sqrt(b**2-4*a*c))/2*a
print ("L'equation a une solution: x = ", x)
else:
x1 = (-b+math.sqrt(b**2-4*a*c))/2*a
x2 = (-b-math.sqrt(b**2-4*a*c))/2*a
print ("L'equation a deux solution: x1 = ", x1, " et x2 =", x2)
In [ ]:
while True:
try:
d = 1/D
print("Possible")
break
except ZeroDivisionError:
print("Division par 0 : impossible")
break
In [ ]:
if D < 0:
print("D=",D)
x1 = (-b+cmath.sqrt(b**2-4*a*c))/2*a
x2 = (-b-cmath.sqrt(b**2-4*a*c))/2*a
print ("L'equation a deux solution: x1 = ", x1, " et x2 =", x2)
In [ ]:
def cuadratica(a,b,c):
a = int(input("ingresar un numero"))
b = int(input("ingresar un numero"))
c = int(input("ingresar un numero"))
Delta = (b**2)-(4*a*c)
print ("Delta = {}".format(Delta))
if Delta < 0:
print ("Pas de solutions reelles")
elif Delta == 0:
x = (-b+math.sqrt(b**2-4*a*c))/2*a
print ("L'equation a une solution: x = {}".format(x))
else:
x1 = (-b+math.sqrt(b**2-4*a*c))/2*a
x2 = (-b-math.sqrt(b**2-4*a*c))/2*a
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
try:
d = 1/Delta
print("Possible")
except ZeroDivisionError:
print("Division par 0 : impossible")
In [ ]:
cuadratica(3,5,1)
In [ ]:
cuadratica(1,2,3)
In [ ]:
def cuadratica(a,b,c):
a = int(input("ingresar un numero"))
b = int(input("ingresar un numero"))
c = int(input("ingresar un numero"))
Delta = (b**2)-(4*a*c)
print ("Delta = {}".format(Delta))
if Delta < 0:
x1 = (-b+cmath.sqrt(b**2-4*a*c))/2*a
x2 = (-b-cmath.sqrt(b**2-4*a*c))/2*a
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
elif Delta == 0:
x = (-b+math.sqrt(b**2-4*a*c))/2*a
print ("L'equation a une solution: x = {}".format(x))
else:
x1 = (-b+math.sqrt(b**2-4*a*c))/2*a
x2 = (-b-math.sqrt(b**2-4*a*c))/2*a
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
try:
d = 1/Delta
print("Possible")
except ZeroDivisionError:
print("Division par 0 : impossible")
x = np.linspace(-10,10,100)
y = a*x**2+b*x+c
plt.plot(x,y)
plt.title("Fonction")
plt.xlabel("x")
plt.ylabel("y")
plt.grid(True)
In [ ]:
cuadratica(1,2,5)
In [125]:
def cuadratica(a,b,c):
""" Esta function resuelve una equation cuadratrica
De la forma ax²+bx+c"""
a = int(input("ingresar un numero"))
b = int(input("ingresar un numero"))
c = int(input("ingresar un numero"))
Delta = (b**2)-(4*a*c)
print ("Delta = {}".format(Delta))
if Delta < 0:
print("L'equation n'a pas de solutions réelles")
x1 = (-b+cmath.sqrt((b**2)-(4*a*c)))/(2*a)
x2 = (-b-cmath.sqrt((b**2)-(4*a*c)))/(2*a)
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
elif Delta == 0:
x = (-b/(2*a))
print ("L'equation a une solution: x = {}".format(x))
else:
x1 = (-b+math.sqrt((b**2)-(4*a*c)))/(2*a)
x2 = (-b-math.sqrt((b**2)-(4*a*c)))/(2*a)
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
try:
d = 1/Delta
print("Possible")
except ZeroDivisionError:
print("Division par 0 : impossible")
x = np.linspace(-5,5,100)
g = (a*x**2)+b*x+c
plt.plot(x,g)
plt.title("Fonction")
plt.xlabel("x")
plt.ylabel("y")
plt.grid(True)
plt.annotate("x1",xy=(x1,0))
plt.annotate("x2",xy=(x2,0))
In [126]:
cuadratica.__doc__
Out[126]:
In [118]:
cuadratica(1,2,3)
In [111]:
cuadratica(1,2,3)
In [134]:
dataset=pd.read_csv("Texet1.txt",sep=" ")
dataset
Out[134]:
In [137]:
dataset["Agnès"]
Out[137]:
In [143]:
dataset=pd.read_csv("Table1.txt",sep=" ")
dataset
Out[143]:
In [152]:
def fonction(x,a,b,c):
return a*x**2+b*x+c
In [157]:
a = 5
b = 2
c = 4
sol = root(fonction,32.8,args=(a,b,c))
sol.x
Out[157]:
In [265]:
def fonction1(c2,D,L,c1,c4,K,k):
j1 = (D/(L/2)*(c1-c2))
c3 = c2/K
j2 = k*(c3-c4)
return (j1-j2)/j1
In [266]:
D = 1.93e-13
L = 146e-6
c1 = 1157
c4 = 0.5
K = 52
k = 7.14e-6
sol = root(fonction1,24,args=(D,L,c1,c4,K,k))
sol.x
Out[266]:
In [ ]:
In [172]:
c1 = np.linspace(1157-112,1157+112,100)
c1
Out[172]:
In [175]:
Longitud = len(c1)
Longitud
Out[175]:
In [176]:
c2 = np.zeros(100)
c2
Out[176]:
In [177]:
c2[4]=5
c2
Out[177]:
In [268]:
D = 1.93e-13
L = 146e-6
c1 = np.linspace(1157-112,1157+112,100)
c4 = 0.5
K = 52
k = 7.14e-6
sol = root(fonction1,15,args=(D,L,c1,c4,K,k))
sol
Out[268]:
In [193]:
c2 = [1.5535421 , 1.55343026, 1.55221984, 1.55101471, 1.54981483,
1.54862016, 1.54743067, 1.54624632, 1.54506709, 1.54389295,
1.54272385, 1.54155976, 1.54040066, 1.5392465 , 1.53809727,
1.53695293, 1.53581344, 1.53467878, 1.53354891, 1.53242381,
1.53130345, 1.53018779, 1.5290768 , 1.52797046, 1.52686874,
1.52577161, 1.52467903, 1.52359099, 1.52250745, 1.52142839,
1.52035378, 1.51928358, 1.51821778, 1.51715634, 1.51609925,
1.51504646, 1.51399796, 1.51295373, 1.51191372, 1.51087793,
1.50984632, 1.50881886, 1.50779554, 1.50677633, 1.5057612 ,
1.50475013, 1.50374309, 1.50274007, 1.50174103, 1.50074595,
1.49975481, 1.49876759, 1.49778426, 1.4968048 , 1.49582919,
1.4948574 , 1.49388941, 1.4929252 , 1.49196475, 1.49100804,
1.49005504, 1.48910573, 1.48816009, 1.4872181 , 1.48627974,
1.48534499, 1.48441383, 1.48348623, 1.48256217, 1.48164165,
1.48072462, 1.47981109, 1.47890101, 1.47799439, 1.47709119,
1.47619139, 1.47529499, 1.47440195, 1.47351226, 1.47262591,
1.47174286, 1.47086311, 1.46998664, 1.46911342, 1.46824344,
1.46737668, 1.46651312, 1.46565275, 1.46479555, 1.4639415 ,
1.46309057, 1.46224277, 1.46139806, 1.46055644, 1.45971788,
1.45888237, 1.45804989, 1.45722042, 1.45639396, 1.45557047]
In [240]:
plt.plot(c1,c2, "b--")
plt.title("c2 = f (c1)")
plt.xlabel("c1")
plt.ylabel("c2")
Out[240]:
In [303]:
def fonction2(c2,D,L,c1,c4,K,k):
j1 = (D/(L/2)*(c1-c2))
c3 = c2/K
j2 = k*(c3-c4)
return (j1-j2)/j1
i = 0
c2 = np.zeros(100)
dimension = np.shape(c2)
print(dimension)
c1 = np.linspace(1157-112,1157+112,100)
D = 1.93e-13
L = 146e-6
c4 = 0.05
K = 52
k = 7.14e-6
for c1i in c1:
sol = root(fonction2,15,args=(D,L,c1i,c4,K,k))
c2[i]= sol.x
i = i + 1
print(c2)
In [258]:
def fonction2(c2,D,L,c1,c4,K,k):
j1 = (D/(L/2)*(c1-c2))
c3 = c2/K
j2 = k*(c3-c4)
return (j1-j2)/j1
In [272]:
D = 1.93e-13
L = 146e-6
c1 = np.linspace(1157-112,1157+112,100)
c4 = 0.05
K = 52
k = 7.14e-6
sol = root(fonction1,15,args=(D,L,c1,c4,K,k))
sol
Out[272]:
In [ ]:
In [304]:
plt.plot(c1,c2, "g--")
plt.title("c2 = f (c1)")
plt.xlabel("c1")
plt.ylabel("c2")
Out[304]:
In [354]:
raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'last_name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze'],
'age': [42, 52, 36, 24, 73],
'preTestScore': [4, 24, 31, 2, 3],
'postTestScore': [25, 94, 57, 62, 70]}
df = pd.DataFrame(raw_data, index = ['exp1', 'exp2', 'exp3','exp4','exp5'],columns = ['first_name', 'last_name', 'age', 'preTestScore', 'postTestScore']
)
df
Out[354]:
In [355]:
df.to_csv('df2')
In [348]:
df["postTestScore"]
Out[348]:
In [ ]:
In [345]:
class Rectangle:
def __init__(self,base, altura):
self.base = base
self.altura = altura
def aire(self):
return self.base*self.altura
def perimetre(self):
return(self.base+self.altura)*2
def volume(self, profondeur):
return self.aire()*profondeur
def __str__(self):
return"{} de {}x{}".format(type(self). name, self.base,self.altura)
In [346]:
r = Rectangle(3,4)
r
Out[346]:
In [343]:
class Polynôme:
def __init__ (dataset=pd.read_csv("fbao.txt",sep=" ")):
def calcul(self):
Delta = (b**2)-(4*a*c)
print ("Delta = {}".format(Delta))
if Delta < 0:
print("L'equation n'a pas de solutions réelles")
x1 = (-b+cmath.sqrt((b**2)-(4*a*c)))/(2*a)
x2 = (-b-cmath.sqrt((b**2)-(4*a*c)))/(2*a)
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
elif Delta == 0:
x = (-b/(2*a))
print ("L'equation a une solution: x = {}".format(x))
else:
x1 = (-b+math.sqrt((b**2)-(4*a*c)))/(2*a)
x2 = (-b-math.sqrt((b**2)-(4*a*c)))/(2*a)
print ("L'equation a deux solution: x1 = {0} et x2 ={1}".format(x1,x2))
try:
d = 1/Delta
print("Possible")
except ZeroDivisionError:
print("Division par 0 : impossible")
x = np.linspace(-5,5,100)
g = (a*x**2)+b*x+c
plt.plot(x,g)
plt.title("Fonction")
plt.xlabel("x")
plt.ylabel("y")
plt.grid(True)
plt.annotate("x1",xy=(x1,0))
plt.annotate("x2",xy=(x2,0))
def garder(self):
df.to_csv
In [ ]: